package cn.mavor.day0920;

public class FileChecker {
    public static void main(String[] args) {
        // 测试数据
        String[] fileNames = {"3_21.rar", "xiaowu.zipa", "张洋.rar", "zhangyang.rar", "张洋.zip", "张洋.java"};
        for (String fileName : fileNames) {
            System.out.println("Is '" + fileName + "' a valid file name? " + isValidFileName(fileName));
        }
    }

    public static boolean isValidFileName(String fileName) {
        if (fileName == null || fileName.isEmpty()) {
            return false;
        }
        int lastDotIndex = fileName.lastIndexOf(".");
        if (lastDotIndex == -1 || lastDotIndex == fileName.length() - 1) {
            return false; // 没有后缀或后缀前没有文件名
        }
        String extension = fileName.substring(lastDotIndex + 1).toLowerCase();
        if (!"zip".equals(extension) && !"rar".equals(extension)) {
            return false; // 后缀不是zip或rar
        }

        String namePart = fileName.substring(0, lastDotIndex);
        if (!namePart.matches("^[\u4e00-\u9fa5]+$")) {
            return false; // 文件名部分不是全中文字符
        }

        return true;
    }
}